from django.db import models


# Create your models here.
# 用户表
class User(models.Model):
    # 主键自增的 ID 字段
    id = models.AutoField(primary_key=True)
    # 唯一的手机号字段
    phone = models.CharField(max_length=11, unique=True)
    # 唯一的昵称字段
    u_name = models.CharField(max_length=20, null=True, blank=True)
    # 唯一的用户名字段
    username = models.CharField(max_length=50, unique=True)
    # 加密的密码字段
    password = models.CharField(max_length=20)
    # 用户类型字段，使用选择选项来明确 1 普通，2 vip，3 管理
    USER_TYPE_CHOICES = (
        (1, '普通'),
        (2, 'vip'),
        (3, '管理'),
    )
    user_type = models.SmallIntegerField(choices=USER_TYPE_CHOICES)
    # 用户头像
    avatar = models.ImageField(upload_to="upload/", null=True, blank=True, verbose_name="图片")
    # 自动记录创建时间的字段
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user'

# 第三方
class ThirdModel(models.Model):

    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户id")
    uid = models.CharField(max_length=255, verbose_name="第三方id")
    token = models.CharField(max_length=255, verbose_name="token")
    types = models.CharField(max_length=10, verbose_name="登录方式", default=1)
    # retoken = models.CharField(max_length=255, verbose_name="retoken", null=True, blank=True)

    class Meta:
        db_table = 'third'

    def __str__(self):
        return self.types
